﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using FlashCards.WebGUI.FlashCardService;

namespace FlashCards.WebGUI
{
    public partial class FlashCardPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // TODO: load user language

            if (!IsPostBack)
            {
                if (Session["CurrentLanguage"] == null)
                    Session["CurrentLanguage"] = new FlashCardsServiceClient().ListLanguages().Where(l => l.TwoLetterISOName == "GB").Single();
                cbxLanguages.SelectedValue = ((Language)Session["CurrentLanguage"]).Id.ToString();
            }
        }

        protected void cbxLanguages_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["CurrentLanguage"] = new FlashCardsServiceClient().ListLanguages().Where(l => l.Id.ToString() == cbxLanguages.SelectedValue).Single();

            // TODO: save user language


            Response.Redirect("FlashCardList.aspx");
        }
    }
}
